#include "sComponentRect.h"
#include "sCRFrame.h"
#include "sCRText.h"
#include "sCREditableText.h"
#include "sCRTouchZone.h"
#include "sGUI.h"

namespace sgui
{
namespace res
{

sComponentRect* cbNewFrame(sGUI& gui) { return new sComponentRectFrame(gui); }
sComponentRect* cbNewText(sGUI& gui) { return new sComponentRectText(gui); }
sComponentRect* cbNewTouchZone(sGUI& gui) { return new sComponentRectTouchZone(gui); }
sComponentRect* cbNewEditableText(sGUI& gui) { return new sComponentRectEditableText(gui); }

const sComponentRect::COMPONENT_RECT_CALLBACK sComponentRect::COMPONENT_RECT_GENERATOR[COMPONENT_RECT_COUNT] = {
	cbNewFrame,
	cbNewText,
    cbNewTouchZone,
    cbNewEditableText
};

sComponentRect* sComponentRect::CreateComponentRect(EComponentRectType type, sGUI& gui)
{
	return COMPONENT_RECT_GENERATOR[type](gui);
}

math::sRectsf& sComponentRect::getRect()
{
	return m_rect;
}

const math::sRectsf& sComponentRect::getRect() const
{
	return m_rect;
}

sComponentAlign& sComponentRect::getAlign()
{
	return m_align;
}

const sComponentAlign& sComponentRect::getAlign() const
{
	return m_align;
}
		
void sComponentRect::load(const db::Record &file)
{
	m_rect.load(file[L"rect"]);
}

void sComponentRect::save(db::Record &file) const
{
	m_rect.save(file[L"rect"]);
	file.Set((u32)getClass());
}

void sComponentRect::clear()
{
	m_rect.clear();
}


#ifdef _EDITOR
void sComponentRect::exportRTTI(rtti::sInfoList& list)
{
	REGISTER_RTTI(L"Rect", TEXT, NEW_RTTI_CLASS_PARAMETER(m_rect));
	REGISTER_RTTI(L"Align", TEXT, NEW_RTTI_CLASS_PARAMETER(m_align));
    REGISTER_RTTI(L"Clip rect", TEXT, NEW_RTTI_PARAMETER(
		BOOL, sComponentRect, this,  &sComponentRect::setClipRect, &sComponentRect::getClipRect
	));
}
#endif

sComponentRect::sComponentRect(sGUI& gui) :
	sGUIObject(gui)
{
	
}

};
};